package com.fulihui.weixinclient.util;

import com.fulihui.weixinclient.result.WeixinJsonResult;
import com.fulihui.weixinclient.result.WeixinXMLResult;

/**
 * 微信接口返回工具
 * Created by Willard.Hu on 2016/3/5.
 */
public class WechatResultUtil {

    /**
     * 检查微信json数据格式的返回结果
     */
    public static void checkResult(WeixinJsonResult result) {
        if (result == null) {
            throw new WechatCheckResultException("null", "result is null");
        }
        if (!result.isSuccess()) {
            throw new WechatCheckResultException(result.getErrcode(), result.getErrmsg());
        }
    }

    /**
     * 检查微信xml数据格式的返回结果
     */
    public static void checkResult(WeixinXMLResult result) {
        if (result == null) {
            throw new WechatCheckResultException("null", "result is null");
        }
        if (!result.getReturn_code().equals(WeixinXMLResult.SUCCESS)) {
            throw new WechatCheckResultException(result.getReturn_code(), result.getReturn_msg());
        }

    }

}
